<template>
  <div class="login">
      <div class="login_title">
          <h1>BIM后台管理系统</h1>
      </div>
      <div class="login_submit">
        <group :title="title_msg">
        <x-input title="用户名" placeholder="请输入用户名" novalidate :icon-type="iconType" :show-clear="false" placeholder-align="left" v-model="account"></x-input>
        </group>
        <group title="">
        <x-input title=" 密码" placeholder="请输入用户密码" novalidate :icon-type="iconType" :show-clear="false" placeholder-align="left" type="password" v-model="password"></x-input>
        </group>
        <div style="padding:15px;" @click="show">
        <x-button @click.native="iconType" type="primary" > 登陆</x-button>
        <!-- <x-button @click.native="iconType = 'error'" type="primary" > 注册</x-button> -->
        </div>
     </div>
     <div class="login_floor">
         <h3>欢迎登陆</h3>
     </div>
  </div>
</template>
<script>
import { XInput, Group, XButton, Cell } from "vux";
import { userInfo } from "os";
import { login, getUser } from "../../api/api";
import { error } from "util";
export default {
  components: {
    XInput,
    XButton,
    Group,
    Cell
  },
  data() {
    return {
      password: "",
      pswInfo: "",
      account: "",
      accountInfo: "",
      iconType: "",
      title_msg:''
    };
  },
  methods: {
    show() {
      var that = this;
      console.log(this.password, this.account);
      const userInfo = {
        userNameOrEmailAddress: this.account,
        password: this.password,
        rememberClient: true
      };
      login(userInfo)
        .then(results => {
          if (results.status === 200) {
            this.iconType = "success"
            const data = results.data;
            console.log(data);
            localStorage.setItem("name", this.account);
            localStorage.setItem("token", data.result.accessToken);
            this.$router.push({ path: "/" });
            let userInfos = {
              accountInfo: true,
              account: this.account,
              userId:data.result.userId,
              userStatus:true
            };
            this.$store.commit('SET_LOGIN',userInfos);
          }
        })
        .catch(error => {
          this.title_msg = '用户名或密码错误！'
          this.iconType = "error"
        });
    }
  }
};
</script>
<style lang="less" scoped>
.login {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px;
  .login_title {
    flex: 1;
    position: relative;
    h1 {
      font-size: 30px;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 100%;
      text-align: center;
    }
  }
  .login_submit {
    flex: 1;
    [data-v-3fdb78a7] {
      margin-top: 10px;
    }
  }
  .login_submit /deep/ .weui-cells:before {
    border-top: none;
  }
  .login_submit /deep/ .weui-cell__hd {
    margin-right: 20px;
  }
  .login_floor {
    font-size: 20px;
    flex: 1;
    text-align: center;
    position: relative;
    h3 {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 100%;
      text-align: center;
    }
  }
}
</style>
